<? 
	include "inc_security.php";	
	//Kiem tra quyen them sua xoa
	checkAddEdit("edit");
	
	$fs_redirect 	= base64_decode(getValue("url","str","GET",base64_encode("listing.php")));
	$record_id 		= getValue("record_id");
	

	$myform = new generate_form();
	$fs_action	= getURL();
	$fs_errorMsg = "";
						   
	//Doan ma nay se thuc thi sau khi nhan nut submit
	$myform = new generate_form();
	$myform->add("med_title", "med_title", 0, 0, "", 1, "Bạn chưa nhập tiêu đề quảng cáo", 0, "");
	$submitform = getValue("action", "str", "POST", "");
	if($submitform == "execute"){
		
		//Check form data
		$fs_errorMsg .= $myform->checkdata();	
		if($fs_errorMsg == ""){
			$upload		= new upload($fs_fieldupload, $fs_filepath, $fs_extension, $fs_filesize);
			$filename	= $upload->file_name;
			if($filename != ""){
				$myform->add("med_value", "filename", 0, 1, "", 0, "", 0, "");
                delete_file($fs_table, $id_field, $record_id, "med_value", $fs_filepath);
				foreach($arr_resize as $type => $arr){
					resize_image($fs_filepath, $filename, $arr["width"], $arr["height"], $arr["quality"], $type);
				}
                $fs_errorMsg = $upload->show_warning_error();unset($upload);
			}
            if($fs_errorMsg == ""){
                $myform->addTable($fs_table);	
    			
    			//Insert to database
    			$myform->removeHTML(0);
    			$db_ex		= new db_execute($myform->generate_update_SQL($id_field, $record_id));
    			
    			redirect("listing.php");
            }
			
			
		}//End if($fs_errorMsg == "")
		
	}//End if($action == "insert")
		
		$myform->addFormname("add_new");
		$myform->evaluate();
		echo $myform->strErrorField;
	/*1). $data_field			: Ten truong
	2). $data_value			: Ten form
	3). $data_type				: Kieu du lieu , 0 : string , 1 : kieu int, 2 : kieu email, 3 : kieu double, 4 : kieu hash password
	4). $data_store			: Noi luu giu data  0 : post, 1 : variable
	5). $data_default_value	: Gia tri mac dinh, neu require thi phai lon hon hoac bang default
	6). $data_require			: Du lieu nay co can thiet hay khong
	7). $data_error_message	: Loi dua ra man hinh
	8). $data_unique			: Chi co duy nhat trong database
	9). $data_error_message2: Loi dua ra man hinh neu co duplicate
	10). $type_form: kiểu form : 1 text ; 2 textarea; 3 kiểu checkbook*/
?>


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<?=$load_header?>
<? 
$myform->checkjavascript();
$fs_errorMsg .= $myform->strErrorField;

//lay du lieu cua record can sua doi
$db_data 	= new db_query("SELECT * FROM " . $fs_table . " WHERE " . $id_field . " = " . $record_id);
if($row 		= mysql_fetch_assoc($db_data->result)){
	foreach($row as $key=>$value){
		if($key!='lang_id' && $key!='admin_id') $$key = $value;
	}	
}else{
		exit();
}
?>
</head>

<body topmargin="0" bottommargin="0" leftmargin="0" rightmargin="0">
<?=template_top(translate_text("Edit advertising"))?>
<img style="position: absolute; top: 50px; right: 50px;" width="100" height="100" border="0" src="/pictures/media/<?=$med_value?>" alt="Không có ảnh"/>
<p align="center" style="padding-left:10px;">
	
    <?
    	$form = new form();
		$form->create_form("add_new",$fs_action,"post","multipart/form-data","onsubmit='validateForm(); return false;'");
		$form->create_table();		
	?>
    <?=$form->text_note('Những ô dấu sao (<font class="form_asterisk">*</font>) là bắt buộc phải nhập.')?>
    <? //Khai bao thong bao loi ?>
    <?=$form->errorMsg($fs_errorMsg)?>
    <?=$form->text("Tiêu đề quảng cáo","med_title","med_title",$med_title,"Tiêu đề quảng cáo",1,250,"",250,"","","")?>
    <?=$form->getFile("Ảnh", $fs_fieldupload, $fs_fieldupload, "Thêm ảnh", 0, 30, "", "")?>
    
    <?=$form->button("submit" . $form->ec . "reset", "submit" . $form->ec . "reset", "submit" . $form->ec . "reset", "Cập nhật" . $form->ec . "Làm lại", "Cập nhật" . $form->ec . "Làm lại", 'style="background:url(' . $fs_imagepath . 'button_1.gif) no-repeat"' . $form->ec . 'style="background:url(' . $fs_imagepath . 'button_2.gif)"', "");?>
	<?=$form->hidden("action", "action", "execute", "");?>
    <?
    $form->close_table();
	$form->close_form();
	unset($form);
	?>
    </p>
<?=template_bottom() ?>
</body>
</html>